package com.xunshibao.tutor.concern;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xunshibao.core.security.Security;
import com.xunshibao.core.security.SecurityUtils;

@Controller
@RequestMapping(value = "/concern/*")
public class ConcernController {
	@Autowired
	private ConcernServiceImpl service;

	@Security
	@RequestMapping(value = "action")
	public @ResponseBody
	Map<String, Object> addConcern(@RequestParam(value = "id") Long infoId,
			@RequestParam(value = "a") Integer action, HttpSession session) {
		Map<String, Object> json = new HashMap<String, Object>();
		Long userId = SecurityUtils.getUserFromSession(session).getUserId();
		int result = 0;
		if (action == 1) { // 添加关注
			result = service.addConern(infoId, userId);
		} else {// 取消关注
			result = service.cancelConern(infoId, userId);
		}
		json.put("status", result);
		return json;
	}
}
